<?php
namespace Admin\Controller;
use Think\Controller;
class LoginController extends Controller {
	
    public function login(){
		if(IS_POST){
			$user = I('user');
			$pwd = I('pwd');
			$captcha = I('captcha');
			$Verify = new \Think\Verify();
			$manager = D('manager');
			if(!$manager->create() ){
				$this->error($manager->getError(),U('login'),1 );
			}

			if( !$Verify->check($captcha) ){
				$this->error('验证码错误',U('login'),1 );
				return;
			}
			if($manager->checkUser($user,$pwd) ){
				$this->success( '登录成功', U('/Admin/Index/index'),1 );
			}else{
				$this->error('账号密码错误',U('login'),1 );
			}

			return;
		}
		$this->display();
    }
	
	public function logout(){
		session('admin',null);
		$this->success('成功退出',U('login'),1 );
	}
	
	public function code(){
		$Verify = new \Think\Verify();
		$Verify->fontSize = 50;
		$Verify->length = 4;
		$Verify->entry();
	}
}